//渲染购物车页面
$(function () {
  function islogin() {
    $.ajax({
      url: "../server/findGoodInCart.php",
      type: "post",
      data: {
        userid,
      },
      success(res) {
        console.log(res);
        let result = JSON.parse(res);
        console.log(result);
        if (!result) {
          $(".cart_empity").show();
        } else {
          $(".cart_top").show();
          $(".total-num").html(`共${result.length}件`);

          let str = "";
          $.each(result, function (index, item) {
            str += `
              <table class="cart_table">
              <tr class="good_item">
                  <td class="td_check">
                      <label class="checkbox_one checkbox_label">
                          <input type="checkbox" class="checkbox_input">
                          <i></i>
                      </label>
                  </td>
                  <td class="td_img">
                      <a href="" class="td_img_a">
                          <img src="${item.good_img}" alt="">
                      </a>
                     
                  </td>
                  <td class="td_info">
                      <div class="td_info_top clear">
                          <div class="fl">
                              <h5>${item.good_name}</h5>
                              <p><span>颜色:A05生黑色;尺码:S</span></p>
                          </div>
                          <div class="fr">
                              <span class="infos_price">${item.good_price}</span>
                              <span class="info_price_old">$680.00</span>
                          </div>
                      </div>
                      <div class="td_info_bottom clear">
                          <p class="fl">
                              <span>数量:</span>
                              <a href="javascript:;" class="num_mins">-</a>
                              <input type="text" name="" id="" value="1" class="num_input">
                              <a href="javascript:;" class="num_add">+</a>
                          </p>
                          <p class="fr">  
                              <a class="delete-one">删除</a>
                          </p>
                      </div>
                  </td>
              </tr>
          </table>`;
          });

          $(".cart_top").append(str);
        }
      },
    });
  }
  const userid = $.cookie("userid");
  if (!userid) {
    $(".cart_empity").show();
    $(".cart_top").hide();
  } else {
    islogin();
  }
});

$(function () {
  changeLogin();
  selfSearch();
});
